import {
  listColumns,
} from './index.const';
import {
  fileDownload
} from '@const/utils.js';
import {
  $loadFileSimply
} from '@const/loadFileOps.js';
import {
  valuePageList,
  queryOriginalFactoryList,
  valueAddedDelete,
  queryProductLineList,
  downloadNewsPaperData,
  downloadAllNewsPaperData
} from '@api/system_config_v1.js';
import ElEditable from '@components/el-editable';

export default {
  components: {
    ElEditable,
  },
  data() {
    return {
      // 多条件查询订单
      tableQuery: {
      },
      tableLoading: false,
      listColumns: listColumns, //表头
      //列表数据
      payload: {},
      loading: false,
      originalFactoryList: [],
      productLineList: [],
      // 主列表分页
      currentPage: 1,
      pageSize: 20,
      multipleSelection: []
    };
  },
  created() {
    this.getList();
    this.initData()
  },
  mounted() {

  },
  methods: {
    initData () {
      this.orderTypeList = [
        {label: '普通订单', value: 'WHOLESALE_ISSUE'},
        {label: '促销订单', value: 'WHOLESALE_PROM'},
        {label: '返利订单', value: 'WHOLESALE_REBATE'},
        {label: '批发-换货', value: 'WHOLESALE_ISSUE'},
        {label: '批发-退货', value: 'WHOLESALE_RETURN'},
        {label: '长期寄售', value: 'LCONSIGN_INIT'},
        {label: '长期寄售确认销货单', value: 'LCONSIGN_ISSUE'},
        {label: '长期寄售-退货', value: 'LCONSIGN_TRANSFER'},
        {label: '长期寄售-换货', value: 'LCONSIGN_INIT'},
        {label: '短期寄售', value: 'SCONSIGN_LENG'}
      ]
    },
    // 重置
    queryFormReset() {
      this.tableQuery = {
      };
      this.saleDate = ['', '']
      this.createDate = ['', '']
      this.currentPage = 1;
      this.getList();
    },
    // 查询
    queryFormQuery() {
      this.currentPage = 1;
      this.getList();
    },
    // 原厂下拉
    queryOriginalFactoryList (val) {
      if (val !== '') {
        this.loading = true;
        let query = {
          originalFactoryName: val,
        };
        this.$axios.$post(queryOriginalFactoryList, query).then(res => {
          this.originalFactoryList = res.payload;
          this.loading = false;
        });
      }
    },
    // 产品线下拉
    queryProductLineList (val) {
      this.loading = true;
      let query = {
        originalFactoryCode: this.tableQuery.vendorNum,
        productLineName: val
      };
      this.$axios.$post(queryProductLineList, query).then(res => {
        this.productLineList = res.payload;
        this.loading = false;
      });
    },
    // 主列表数据
    getList() {
      this.tableLoading = true;
      const query = {
        ...this.tableQuery,
        page: this.currentPage,
        pageSize: this.pageSize
      };
      this.$axios.$post(valuePageList, query).then(res => {
        if (res.code === '0') {
          res.payload.content = res.payload.content || []
          this.payload = res.payload;
        }
        this.tableLoading = false;
      });
    },
    // 主列表分页器
    reloadProductData(val) {
      this.currentPage = val.number
      this.pageSize = val.size
      this.getList();
    },
    //表格选择数据
    selectionChange(val) {
      this.multipleSelection = val
    },
    onAdd () {
      this.$router.push({
        path: '/system-config/value-added-configuration/detail'
      })
    },
    onEdit (item) {
      this.$router.push({
        path: '/system-config/value-added-configuration/detail',
        query: {
          id: item.id,
          appendFieldId: item.appendFieldId
        }
      })
    },
    onDelete (item) {
      this.$confirm('确定要删除该数据吗?', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const url = valueAddedDelete + '/' + item.id
        this.$axios.$get(url).then(res => {
          this.getList()
          this.$message.success('删除成功')
        })
      }).catch(() => {
        this.$message.info('已取消删除')
      })
    }
  }
};
